import pulpcore.CoreSystem;
import pulpcore.Stage;
import pulpcore.image.Colors;
import pulpcore.image.CoreFont;
import pulpcore.image.CoreImage;
import pulpcore.scene.Scene2D;
import pulpcore.sprite.Button;
import pulpcore.sprite.FilledSprite;
import pulpcore.sprite.Group;
import pulpcore.sprite.Label;
import pulpcore.sprite.Sprite;

public class InfoBar extends Group
{
	final static float HEIGHT = 50f;
	public static InfoBar instance = null;

	public Label p1Score;
	public Label p2Score;

	Player p1;
	Player p2;
	
	private Button muteButton;
	Button infoButton;

	public InfoBar(TwoPlayerScene scene,Player p1, Player p2)
	{
		super(0, Stage.getHeight() - HEIGHT, Stage.getWidth(), HEIGHT);

		this.p1 = p1;
		this.p2 = p2;
		instance = this;

		add(new FilledSprite(Colors.BLACK));

		CoreFont f1 = CoreFont.getSystemFont().tint(Colors.WHITE);
		CoreFont f2 = f1.scale(2);
		CoreFont blue = f2.tint(Colors.BLUE);
		CoreFont red = f2.tint(Colors.RED);

		p1Score = new Label(blue, "%d", width.get() / 2 + 20, 2);
		p1Score.setAnchor(Sprite.NORTH);
		p1Score.setFormatArg(p1.score);
		p2Score = new Label(red, "%d", width.get() / 2 - 20, 2);
		p2Score.setAnchor(Sprite.NORTH);
		p2Score.setFormatArg(p2.score);
		add(p1Score);
		add(p2Score);

		Label winningScore = new Label(f1, "Score to win: %d", width.get() / 2, 30);
		winningScore.setFormatArg(scene.winningScore);
		winningScore.setAnchor(Sprite.NORTH);
		add(winningScore);

		muteButton = new Button(CoreImage.load("mute.png").tint(Colors.WHITE).split(3, 2), width.get() - 30, height
				.get() / 2, true);
		muteButton.setSelected(!CoreSystem.isMute());
		muteButton.setAnchor(Sprite.CENTER);
		muteButton.setPixelLevelChecks(false);
		add(muteButton);

		infoButton = Button.createLabeledButton("Help", 5, (int) height.get() / 2);
		infoButton.setAnchor(Sprite.WEST);
		add(infoButton);

		Sounds s = new Sounds();
	}

	@Override
	public void update(int elapsedTime)
	{
		super.update(elapsedTime);
		if (muteButton.isClicked())
		{
			CoreSystem.setMute(!muteButton.isSelected());
		}
		if (infoButton.isClicked())
		{
			if (Stage.getScene() instanceof HelpScene)
				Stage.popScene();
			else
				Stage.pushScene(new HelpScene());
		}
	}

}
